package com.training.java.module2;
import java.util.*;
import java.io.*;
/**
 * Created with IntelliJ IDEA.
 * User: Vladislav
 * Date: 24.10.13
 * Time: 17:18
 * To change this template use File | Settings | File Templates.
 */
public class Authentication {
    private User user;
   // private final String PATH = "users.txt";
    public Authentication(String Path) throws FileNotFoundException {
        boolean correctUser = false;
        Scanner in = new Scanner(System.in);
        while(!correctUser) {
            System.out.print("Enter  username");
            String name = in.nextLine();
            System.out.print("Enter  password");
            String password = in.nextLine();
            user = new User(name,password);
            Scanner users = new Scanner(new File(Path));
            correctUser = false;
            while((!correctUser) && (users.hasNext())) {
                String username = users.next();
                String userPassword = users.next();
                correctUser = user.isCorrectUser(username,userPassword);
            }
        }
    }
    public User getUser() {
        return user;
    }
}
